<form id="myform" lay-filter="metadatatableform" class="layui-form layui-form-pane" action="" style="margin: 5px">
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">版本号</label>-->
        <!--<div class="layui-input-block">-->
            <!--<select id="versionid" name="versionid" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input"/>-->
        <!--</div>-->
    <!--</div>-->
    <div class="layui-form-item">
        <label class="layui-form-label">数据库</label>
        <div class="layui-input-block" >
            <input id="databaseId" lay-filter="test1" type="text" name="databaseId" required lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">编号</label>
        <div class="layui-input-block" >
            <input id="id" lay-filter="test1" type="text" name="id" required lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">表名称</label>
        <div class="layui-input-block" >
            <input id="name" lay-filter="test1" type="text" name="name" required lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">创建人</label>
        <div class="layui-input-block" >
            <input id="createperson" lay-filter="test1" type="text" name="createperson" required lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">修改人</label>
        <div class="layui-input-block" >
            <input id="makerperson" lay-filter="test1" type="text" name="makerperson" required lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">最近一次更新时间</label>
        <div class="layui-input-block" >
            <input id="lastupdatetime" lay-filter="test1" type="text" name="lastupdatetime" required lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">首次更新时间</label>
        <div class="layui-input-block" >
            <input id="updateTime" lay-filter="test1" type="text" name="updateTime" required lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">最近一次更新目的</label>
        <div class="layui-input-block" >
            <input id="lastupdategoal" lay-filter="test1" type="text" name="lastupdategoal" required lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">
        </div>
    </div>

    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">使用状态</label>-->
        <!--<div class="layui-input-block" >-->
            <!--<input id="userflag" lay-filter="test1" type="text" name="userflag" required lay-verify="required" placeholder="请输入唯一标识名称（英文）" autocomplete="off" class="layui-input">-->
        <!--</div>-->
    <!--</div>-->

    <div class="layui-form-item">
        <label class="layui-form-label">使用状态</label>
        <div class="layui-input-block">
            <input type="checkbox" lay-skin="switch" id="switch" name="switch">
            <input id="userflag" type="hidden" name="userflag" required>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['jquery','baajax','form'], function(){
        var form = layui.form;
        var ajax=layui.baajax;
        var $=layui.jquery;
        getInfo();
        // layer.alert("test : "+$("#switch").attr('checked'));
        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));

            var metadatatable=data.field;
            // var metadatatable.switch;
            // layer.alert($("#switch").attr('checked'));
            var switchFlag=$("#switch").attr('checked');
            if(switchFlag==='checked'){
                data.field.userflag=1;
            }else{
                data.field.userflag=0;
            }
            // alert(data.field);
            ajax.put("/metadatatable",data.field, function (data) {
                    if(data.code=='200'){
                        //layer.msg('添加成功');
                        layer.confirm('修改成功,是否继续修改?', {icon: 3, title:'提示'}, function(index){
                            //form.render(null, 'test1');
                            // $("#myform").get(0).reset();
                            layer.close(index);
                        },function(index){
                            //table.refresh();
                            layer.closeAll();
                        });
                    }
                    // var ret = data;
                    // succFunc(ret, paras);
                },function (data) {
                    layer.msg('失败');
                    // errorFunc();
                });
            return false;
        });
        //监听连接测试提交
        // form.on('submit(connect_test)', function(data){
        //     layer.msg(JSON.stringify(data.field));
        //     $.ajax({
        //         type: "POST",
        //         url: "/metadatadatabase/connectTest",
        //         dataType: "json",
        //         data: data.field,
        //         cache: true,
        //         async: false,
        //         success: function (data) {
        //             if(data.code=='200'){
        //                 layer.msg('连接成功');
        //             }else{
        //                 layer.msg('连接失败');
        //             }
        //             // var ret = data;
        //             // succFunc(ret, paras);
        //         },
        //         error: function () {
        //             layer.msg('请求失败');
        //             // errorFunc();
        //         }
        //     })
        //     return false;
        // });

        function getInfo(){
            ajax.syncGet("/metadatatable/"+$("#layer_metadata-tableId").val(),{},function (data) {
                //if(data.code=='200'){
                //layer.msg('添加成功');
                $("#id").val(data.id);
                $("#name").val(data.name);
                $("#userflag").val(data.userflag);
                $("#checkTime").val(data.checkTime);
                $("#createperson").val(data.createperson);
                $("#createtime").val(data.createtime);
                $("#databaseId").val(data.databaseId);
                $("#lastupdategoal").val(data.lastupdategoal);
                $("#lastupdatetime").val(data.lastupdatetime);
                $("#makerperson").val(data.makerperson);
                $("#updateTime").val(data.updateTime);
                // $("#answer").val(data.answer);
                // $("#operator").val(data.operator);
                // alert(data.userflag);
                var flag=false;
                if(data.userflag===1){
                    flag=true;
                    // $("#switch").prop('checked','checked');
                }else{
                    // $("#switch").removeAttr('checked');
                }
                form.render('checkbox');
                form.val("metadatatableform", {

                    "id": data.id // "name": "value"
                    ,"name": data.name // "name": "value"
                    ,"userflag": data.userflag // "name": "value"
                    ,"check[write]": true
                    ,"switch": flag
                    ,"desc": "我爱layui"
                })
                //}
            },function () {
                layer.msg('查询失败');
            });
        }
    });
</script>